package com.zxn.controller;

import com.zxn.service.WorkPositionDataProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * program: springbootelastic
 * description: 位置区域分析
 * author: zxn
 * create: 2019-03-17 20:41
 **/
@RestController
@Api(description="位置区域分析")
public class WorkPositionDataProcessController {

    @Autowired
    private WorkPositionDataProcessService workPositionDataProcessService;

    @PostMapping("/insertAreaData")
    @ApiOperation("添加区域数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaName", value = "区域名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "positions", value = "区域位置：例如：经度_纬度，按顺序进行", required = false, dataType = "String", paramType = "query")
    })
    public void insertAreaData(String areaName,String positions){
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        workPositionDataProcessService.addAreaToElastic(areaName,id,positions);
    }

    @PostMapping("/insertLineData")
    @ApiOperation("添加线段数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineName", value = "线段名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "positions", value = "线段位置：例如：经度_纬度，按顺序进行", required = false, dataType = "String", paramType = "query")
    })
    public void insertLineData(String lineName,String positions){
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        workPositionDataProcessService.addLineToElastic(lineName,id,positions);
    }

    @DeleteMapping("/deleteWorkPosition")
    @ApiOperation("删除区域线段数据")
    @ApiImplicitParam(name = "id", value = "区域线段id", required = false, dataType = "String", paramType = "query")
    public void deleteWorkPosition(String id){
        workPositionDataProcessService.deleteWorkPositionById(id);
    }

    @PostMapping("/insertPointData")
    @ApiOperation("添加点数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointName", value = "线段名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lgitude", value = "经度", required = false, dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", required = false, dataType = "Double", paramType = "query")
    })
    public  void insertPointData(String pointName,Double lgitude,Double latitude ){
        String id = UUID.randomUUID().toString().replaceAll("-","");
        workPositionDataProcessService.addPointDataToElastic(id,pointName,lgitude,latitude);
    }

    @DeleteMapping("/deletePointData")
    @ApiOperation("删除点数据")
    @ApiImplicitParam(name = "id", value = "点id", required = false, dataType = "String", paramType = "query")
    public void deletePointData(String id){
        workPositionDataProcessService.deletePointData(id);
    }


}
